<template>
  <body id="poster">
  <el-form :rules="rules" class="login-container" label-position="left" ref="loginForm"
           label-width="0px" :model="loginForm">
    <h3 class="login_title">Anthony酒店系统登录</h3>
    <el-form-item prop="name">
      <el-input type="text" v-model="loginForm.name"
                auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input type="password" v-model="loginForm.password"
                auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item style="width: 100%">
      <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="submitLogin">登录</el-button>
    </el-form-item>
  </el-form>
  </body>
</template>

<script>
  export default {
    name: 'Login',
    data () {
      return {
        loginForm: {
          name: '',
          password: ''
        },
        rules:{
          name: [{required: true, message: '请输入用户名', trigger:'blur'}],
          password: [{required: true, message: '请输入密码', trigger:'blur'}]
        },
        responseResult: [],
        userToken:''
      }
    },
    methods: {
      submitForm(formname) {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      submitLogin() {
        var _this = this
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            this.$axios
              .post('/login', {
                name: this.loginForm.name,
                password: this.loginForm.password
              })
              .then(resp => {
                if(resp.code === '200') {
                  if(this.$store.state.token) {
                    this.$router.push('/admin')
                  }else{
                    this.$router.replace('/login');
                  }
                }
              })
          } else {
            this.$message.error('请输入所有字段！');
            return false;
          }
        });
      }
    }
  }
</script>

<style>
  #poster {
    background: url("../assets/login.jpg") no-repeat center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
  }
  body{
    margin: 0px;
  }
  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }

</style>

